
import {
    format
    
} from '@/utils/tool'

import FileSaver from 'file-saver'
import XLSX from 'xlsx'

export default {
    data () {
        return {
            maxsize: 10000,
            checkStatusData: [{
                label: '待审核',
                value: '0'
            }, {
                label: '通过',
                value: '1'
            }, {
                label: '拒绝',
                value: '2'
            }],
            schoolData: [],
            majorData: [],
            gradeData: [],
            termData: [],
            levelData: [],
            tableSelection: []
        }
    },
    methods: {
        exec (type) {
            if (type == "toExamine") {

            }
        },
        exportToExcel (countData, filname) {
            const fileName = filname ? filname : '导出列表.xlsx'

            // let et = XLSX.utils.table_to_book(document.getElementById('table-content')); //此处传入table的DOM节点
            // let etout = XLSX.write(et, {
            //     bookType: 'xlsx',
            //     bookSST: true,
            //     type: 'array'
            // });
            try {
                FileSaver.saveAs(new Blob([countData], {
                    type: 'application/octet-stream'
                }), fileName);   //trade-publish.xlsx 为导出的文件名
            } catch (e) {
                console.log(e);
            }
            return true;
        },
        ossUri (d, s) {
            return ossUri(d, s);
        },
        format (d, f) {
            return format.Date(d, f)
        },
        handleSizeChange (v) {
            this.searchForm.size = v;
            this.search()
        },
        handleCurrentChange (v) {
            this.searchForm.current = v;
            this.search()
        },
        handleReset () {
            this.$refs.searchForm.resetFields();
            this.searchForm.current = 1;
            this.search()
        },
        tableSelectionChange (val) {
            this.tableSelection = val;
        },
        getSchoolData (data) {
            /*
            data:{teacherName:'',schoolName:''}
            */
            var this_=this;
           return new Promise(function(resolve, reject) {
                //获取学校列表
                this_.$api.school.schoolList({
                    current: 1,
                    size: this_.maxsize,
                    ...data
                }).then(d => {
                    this_.schoolData = d.data;
                    resolve(d.data)
                }).catch(e => {
                    console.log(e);
                    reject(e)
                })
            })
        },
        getMajorData (data) {
            /*
            data:{schoolId:0,majorName:''}
            */
            //获取专业列表
            this.$api.major.schoolMajorList({
                current: 1,
                size: this.maxsize,
                ...data
            }).then(d => {
                this.majorData = d.data;
            }).catch(e => {
                console.log(e);
            })
        },
        getGradeData (data) {
            /*
            data:{schoolId:0,gradeName:''}
            */
            //获取专业列表
            this.$api.school.classList({
                current: 1,
                size: this.maxsize,
                ...data
            }).then(d => {
                this.gradeData = d.data;
            }).catch(e => {
                console.log(e);
            })
        },
        getTermData (data) {
            /*
            data:{schoolId:0,gradeId:0,termName:''}
            */
            //获取学期列表
            this.$api.school.yearList({
                current: 1,
                size: this.maxsize,
                ...data
            }).then(d => {
                this.termData = d.data;
            }).catch(e => {
                console.log(e);
            })
        },
        getDictData (code, name) {
            //获取层次
            this.$api.dict.pkey({
                pkey: code
            }).then(d => {
                d.data.forEach(e => {
                    e[name + 'Id'] = e.dictId
                    e[name + 'Name'] = e.dictName
                })
                this[name + 'Data'] = d.data;
                if (this.allData) {
                    this.allData[name + 'Data'] = d.data;
                }
            }).catch(e => {
                console.log(e);
            })
        }
    }
}